<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Calculators:  Stock Calculator</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="JavaScript Source Code 3000">
<META NAME="section" CONTENT="Calculators">
<META NAME="description" CONTENT="Deciding when to buying and sell stocks is difficult enough - figuring the profit or loss from that trade shouldn't have to be.  Just enter the number of shares, your purchase price, your selling price, and the commission fees for the trade and this script instantly figures your resulting profit or loss after commission fees.">

<SCRIPT LANGUAGE="JavaScript">




<!-- Begin
function round(num) {
amount = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
amount -= 0;
// .99 cent format courtsey of Martin Webb
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function dectable() {
windowprops = 'personalbar=no,toolbar=no,' +
'status=no,scrollbars=yes,location=no,' +
'resizable=yes,menubar=no,width=340,height=400';
decimalWin=window.open('', 'table', windowprops);

text = "<html><body><table width=300 cellpadding=0 cellspacing=1>";
text += "<tr><td bgcolor='#333366' align=center><font face='arial";
text += ",helvetica' size=2 color='#ffffff'><b>Fractional Price</";
text += "b></font></td><td bgcolor='#333366' align=center><font f";
text += "ace='arial,helvetica' size=2 color='#ffffff'><b>Dollar E";
text += "quivalent</b></font></td></tr><tr align=center><td align";
text += "=center><font face='arial,helvetica' size=2>1/32<br>1/16";
text += "<br>3/32<br>1/8<br>5/32<br>3/16<br>7/32<br>1/4<br>9/32<b";
text += "r>5/16<br>11/32<br>3/8<br>13/32<br>7/16<br>15/32<br>1/2<";
text += "br>17/32<br>9/16<br>19/32<br>5/8<br>21/32<br>11/16<br>23";
text += "/32<br>3/4<br>25/32<br>13/16<br>27/32<br>7/8<br>29/32<br";
text += ">15/16<br>31/32<br>1</td><td align=center><font face='ar";
text += "ial,helvetica' size=2>$0.03125<br>$0.06250<br>$0.09375<b";
text += "r>$0.12500<br>$0.15625<br>$0.18750<br>$0.21875<br>$0.250";
text += "00<br>$0.28125<br>$0.31250<br>$0.34375<br>$0.37500<br>$0";
text += ".40625<br>$0.43750<br>$0.46875<br>$0.50000<br>$0.53125<b";
text += "r>$0.56250<br>$0.59375<br>$0.62500<br>$0.65625<br>$0.687";
text += "50<br>$0.71875<br>$0.75000<br>$0.78125<br>$0.81250<br>$0";
text += ".84375<br>$0.87500<br>$0.90625<br>$0.93750<br>$0.96875<b";
text += "r>$1.00000</td></tr></table></body></html>";

decimalWin.document.open();
decimalWin.document.writeln(text);
decimalWin.document.close();
}

function stocks(form) {
shares = form.shares.value * 1;

buyprice = form.buyprice.value * 1;
buycomm = form.buycomm.value * 1;

sellprice = form.sellprice.value * 1;
sellcomm = form.sellcomm.value * 1;

bought = round(parseFloat(shares * buyprice) + buycomm); // price for purchase
sold = round(parseFloat(shares * sellprice) - sellcomm); // price sold for
result = round(sold - bought);

form.buycost.value  = "$ " + bought;
form.sellcost.value = "$ " + sold;
form.result.value = "$ " + result;
}
//  End -->
</script>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff>

<BR>
<center>
<table width=600 cellpadding=0 cellspacing=10>
<tr>
<td width=468 align=center>

    
    
</td>
<td width=120 align=center>
    
</td>
</tr>
</table>
<BR>
<BR>
<basefont size=3>
<FONT SIZE="+2" FACE="Helvetica,Arial">
<A HREF="../index.htm" /" TARGET="_top"><FONT COLOR="#0000FF"><b>Home</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<A HREF="index.htm" /calculators/"><font color="#FF0000"><b>Calculators</b></font></A>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}">
<FONT COLOR="#006666"><b>Stock Calculator</b></font></font>
<BR>
<BR>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->
Deciding when to buying and sell stocks is difficult enough - figuring the profit or loss from that trade shouldn't have to be.  Just enter the number of shares, your purchase price, your selling price, and the commission fees for the trade and this script instantly figures your resulting profit or loss after commission fees.
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<center>
<form name='stockform'>
<table border=1>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Shares</td>
<td><input type=text name=shares size=11></td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Symbol</td>
<td><input type=text name=symbol size=11></td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Purchase Price</td>
<td><input type=text name=buyprice size=8> *</td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Sell Price</td>
<td><input type=text name=sellprice size=8> *</td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Buy commission</td>
<td><input type=text name=buycomm size=11></td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Sell Commission</td>
<td><input type=text name=sellcomm size=11></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=button name=calc value="Calculate Trade" onClick="javascript:stocks(this.form)">
</td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Purchased For</font></td>
<td align=center><input type=text name=buycost size=11></td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Sold For</font></td>
<td align=center><input type=text name=sellcost size=11></td>
</tr>
<tr>
<td align=center><font face="arial, helvetica" size="-1">Result</font></td>
<td align=center><input type=text name=result size=11></td>
</tr>
</table>
<p>
<font face="arial, helvetica" size="-2">
* <a href="javascript:dectable();">Remember to convert fractions to decimals!</a>
</font>
</form>
</center>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Calculators:  Stock Calculator</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!
<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  4.59 KB" size=24>
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- TWO STEPS TO INSTALL STOCK CALCULATOR:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  --&gt;

&lt;!-- STEP ONE: Paste this code into the HEAD of your HTML document  --&gt;

&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin
function round(num) {
amount = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
amount -= 0;
// .99 cent format courtsey of Martin Webb
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function dectable() {
windowprops = 'personalbar=no,toolbar=no,' +
'status=no,scrollbars=yes,location=no,' +
'resizable=yes,menubar=no,width=340,height=400';
decimalWin=window.open('', 'table', windowprops);

text = "&lt;html&gt;&lt;body&gt;&lt;table width=300 cellpadding=0 cellspacing=1&gt;";
text += "&lt;tr&gt;&lt;td bgcolor='#333366' align=center&gt;&lt;font face='arial";
text += ",helvetica' size=2 color='#ffffff'&gt;&lt;b&gt;Fractional Price&lt;/";
text += "b&gt;&lt;/font&gt;&lt;/td&gt;&lt;td bgcolor='#333366' align=center&gt;&lt;font f";
text += "ace='arial,helvetica' size=2 color='#ffffff'&gt;&lt;b&gt;Dollar E";
text += "quivalent&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr align=center&gt;&lt;td align";
text += "=center&gt;&lt;font face='arial,helvetica' size=2&gt;1/32&lt;br&gt;1/16";
text += "&lt;br&gt;3/32&lt;br&gt;1/8&lt;br&gt;5/32&lt;br&gt;3/16&lt;br&gt;7/32&lt;br&gt;1/4&lt;br&gt;9/32&lt;b";
text += "r&gt;5/16&lt;br&gt;11/32&lt;br&gt;3/8&lt;br&gt;13/32&lt;br&gt;7/16&lt;br&gt;15/32&lt;br&gt;1/2&lt;";
text += "br&gt;17/32&lt;br&gt;9/16&lt;br&gt;19/32&lt;br&gt;5/8&lt;br&gt;21/32&lt;br&gt;11/16&lt;br&gt;23";
text += "/32&lt;br&gt;3/4&lt;br&gt;25/32&lt;br&gt;13/16&lt;br&gt;27/32&lt;br&gt;7/8&lt;br&gt;29/32&lt;br";
text += "&gt;15/16&lt;br&gt;31/32&lt;br&gt;1&lt;/td&gt;&lt;td align=center&gt;&lt;font face='ar";
text += "ial,helvetica' size=2&gt;$0.03125&lt;br&gt;$0.06250&lt;br&gt;$0.09375&lt;b";
text += "r&gt;$0.12500&lt;br&gt;$0.15625&lt;br&gt;$0.18750&lt;br&gt;$0.21875&lt;br&gt;$0.250";
text += "00&lt;br&gt;$0.28125&lt;br&gt;$0.31250&lt;br&gt;$0.34375&lt;br&gt;$0.37500&lt;br&gt;$0";
text += ".40625&lt;br&gt;$0.43750&lt;br&gt;$0.46875&lt;br&gt;$0.50000&lt;br&gt;$0.53125&lt;b";
text += "r&gt;$0.56250&lt;br&gt;$0.59375&lt;br&gt;$0.62500&lt;br&gt;$0.65625&lt;br&gt;$0.687";
text += "50&lt;br&gt;$0.71875&lt;br&gt;$0.75000&lt;br&gt;$0.78125&lt;br&gt;$0.81250&lt;br&gt;$0";
text += ".84375&lt;br&gt;$0.87500&lt;br&gt;$0.90625&lt;br&gt;$0.93750&lt;br&gt;$0.96875&lt;b";
text += "r&gt;$1.00000&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;";

decimalWin.document.open();
decimalWin.document.writeln(text);
decimalWin.document.close();
}

function stocks(form) {
shares = form.shares.value * 1;

buyprice = form.buyprice.value * 1;
buycomm = form.buycomm.value * 1;

sellprice = form.sellprice.value * 1;
sellcomm = form.sellcomm.value * 1;

bought = round(parseFloat(shares * buyprice) + buycomm); // price for purchase
sold = round(parseFloat(shares * sellprice) - sellcomm); // price sold for
result = round(sold - bought);

form.buycost.value  = "$ " + bought;
form.sellcost.value = "$ " + sold;
form.result.value = "$ " + result;
}
//  End --&gt;
&lt;/script&gt;
&lt;/HEAD&gt;

&lt;!-- STEP TWO: Copy this code into the BODY of your HTML document  --&gt;

&lt;BODY&gt;

&lt;center&gt;
&lt;form name='stockform'&gt;
&lt;table border=1&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Shares&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=shares size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Symbol&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=symbol size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Purchase Price&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=buyprice size=8&gt; *&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Sell Price&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=sellprice size=8&gt; *&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Buy commission&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=buycomm size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Sell Commission&lt;/td&gt;
&lt;td&gt;&lt;input type=text name=sellcomm size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan=2 align=center&gt;
&lt;input type=button name=calc value="Calculate Trade" onClick="javascript:stocks(this.form)"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Purchased For&lt;/font&gt;&lt;/td&gt;
&lt;td align=center&gt;&lt;input type=text name=buycost size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Sold For&lt;/font&gt;&lt;/td&gt;
&lt;td align=center&gt;&lt;input type=text name=sellcost size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=center&gt;&lt;font face="arial, helvetica" size="-1"&gt;Result&lt;/font&gt;&lt;/td&gt;
&lt;td align=center&gt;&lt;input type=text name=result size=11&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;
&lt;font face="arial, helvetica" size="-2"&gt;
* &lt;a href="javascript:dectable();"&gt;Remember to convert fractions to decimals!&lt;/a&gt;
&lt;/font&gt;
&lt;/form&gt;
&lt;/center&gt;

 

&lt;!-- Script Size:  4.59 KB --&gt;</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>
